home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 6847 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  922 b 

  1. Path: rs6.iaee.tuwien.ac.at!sor
  2. From: sor@rs6.iaee.tuwien.ac.at (Evgeni Sorokin)
  3. Newsgroups: comp.lang.c
  4. Subject: How do I round and truncate floats to integers?
  5. Date: 15 Feb 1996 19:07:23 GMT
  6. Organization: Vienna University of Technology, Austria
  7. Message-ID: <4g009b$c2n@news.tuwien.ac.at>
  8. NNTP-Posting-Host: rs6.iaee.tuwien.ac.at
  9. X-Newsreader: TIN [version 1.2 PL2]
  10.  
  11. Hello!
  12.  
  13. I am myself ashamed of posting such stupid questions, but FAQ's and
  14. books that I've found assume this to be too evident.
  15.  
  16. Given a float (double, to be exact) how do I 
  17.  
  18. 1) round it to nearest integer (forget 0.5 problem for the moment) and
  19. 2) truncate it to the integer?
  20.  
  21. I browsed include directories of my compilers (Turbo C and GNU) and
  22. have not found passing functions taking floats and returning
  23. integers. If typecasting is supposed to do the trick, then how do I
  24. distinguish cases 1) and 2)?
  25.  
  26.  
  27. Many thanks in advance.
  28.  
  29. --
  30. Zhenya Sorokin
  31.  
  32.  
  33.